package org.nt4b.schemadoc.core.in;

import java.io.InputStream;
import java.io.Reader;

import org.nt4b.schemadoc.core.dom.Column;
import org.nt4b.schemadoc.core.dom.SchemaComments;
import org.nt4b.schemadoc.core.dom.Table;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;


public class XMLCommentsReader {
    private XStream getXStream() {
        final XStream xstream = new XStream(new DomDriver());
        xstream.alias("schema", SchemaComments.class);
        xstream.alias("table", Table.class);
        xstream.alias("column", Column.class);
        return xstream;
    }
    
    public SchemaComments readSchema(final InputStream inputStream) {
        final XStream xstream = getXStream();
        final SchemaComments result = (SchemaComments) xstream.fromXML(inputStream);
        return result;
    }
    
    public SchemaComments readSchema(final Reader reader) {
        final XStream xstream = getXStream();
        final SchemaComments result = (SchemaComments) xstream.fromXML(reader);
        return result;
    }
    
}
